package com.william.jdbcplus.demo.config;

import com.william.jdbcplus.boot.starter.constant.DataSourceConstant;
import com.william.jdbcplus.core.ds.DynamicDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 配置事务管理器
 * 开启事务管理,确保在启动类中@component扫描到该类
 */
@EnableTransactionManagement
@Configuration
public class TransactionConfig {
    @Bean(name = "transactionManager")
    public PlatformTransactionManager TransactionManagerBean(@Qualifier(DataSourceConstant.DYNAMIC) DynamicDataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
}